Inject the Mongoose Connection with @InjectConnection() and call startSession() to create a session. Start a transaction on the session and pass { session } to every query that must participate. Commit on success, abort on error, and always end the session in a finally block.
Mongoose transactions require a MongoDB replica set — single-node standalone instances do not support them.
Use @InjectConnection() to get the Mongoose Connection for creating sessions.
Pass { session } to every query inside the transaction or the operation runs outside it.
Model.create() with a session requires the array form: create([data], { session }).
Always call session.endSession() in finally — not releasing it leaks the session from the pool.